package com.sptpc.demo.controller;

import com.sptpc.demo.model.Category;
import com.sptpc.demo.model.Drink;
import com.sptpc.demo.model.Student;
import com.sptpc.demo.service.ICategoryService;
import com.sptpc.demo.service.IDrinkService;
import com.sptpc.demo.service.IStudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;
@Slf4j
@Controller
public class RouterController {
    @Autowired
    public IDrinkService drinkService;
    @Autowired
    public ICategoryService categoryService;
    @Autowired
    public IStudentService studentService;
    // 首页（登录）路由
    @GetMapping("/")
    public String index() {
        return "manage/login";
    }

    // 后台首页路由
    @GetMapping("/manage/index")
    public String adminIndex() {
        return "manage/index";
    }

    // 后台欢迎页面路由
    @GetMapping("/manage/welcome")
    public String welcome() {
        return "manage/welcome";
    }

    //////////////////////////////////
    //           饮品管理            //
    //////////////////////////////////
    // 饮品管理首页路由
    @GetMapping("/menu/drink")
    public String drinkIndex() {
        return "drink/index";
    }

    // 饮品添加页路由
    @GetMapping("/drink/addform")
    public String drinkAddFrom() {
        return "drink/add";
    }

    // 饮品修改页路由
    // get /drink/updateform?id=13
    @GetMapping("/drink/updateform")
    public ModelAndView drinkUpdateFrom(@RequestParam Long id) {
        ModelAndView mv = new ModelAndView("drink/edit");
        Drink drink = drinkService.getDrinkById(id);
        log.info("ss",drink);
        mv.addObject("data", drink);
        return mv;
    }

    //////////////////////////////////
    //           分类管理            //
    //////////////////////////////////

    // 分类管理首页路由
    @GetMapping("/menu/category")
    public String categoryIndex() {
        return "category/index";
    }

    //分类添加页路由
    @GetMapping("/category/addform")
    public String categoryAddFrom() {
        return "category/add";
    }

    //分类更新路由
    // get /category/updateform?id=2
    @GetMapping("/category/updateform")
    public ModelAndView categoryUpdateFrom(@RequestParam Long id) {
        ModelAndView mv = new ModelAndView("category/edit");
        Category category = categoryService.getCategoryById(id);
        mv.addObject("data", category);
        return mv;
    }

    //////////////////////////////////
    //           学生管理            //
    //////////////////////////////////
    //学生管理路由
    @GetMapping("/menu/stu")
    public String studentIndex() {
        return "student/index";
    }
    //学生添加页路由
    @GetMapping("/student/addform")
    public String studentAddFrom() {
        return "student/add";
    }

    @GetMapping("/student/updateform")
    public ModelAndView studentUpdateFrom(@RequestParam Long id) {
        ModelAndView mv = new ModelAndView("student/edit");
        Student student = studentService.getStudentByID(id);
        mv.addObject("studentData",student);
        return mv;
    }
}
